package com.bee.gateway.runner;

import com.bee.gateway.service.IgnoreAuthService;
import com.bee.gateway.service.RoutesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author Damin.yang
 * @date 2019/07/30 16:55
 */
@Component
@Slf4j
public class Runner implements ApplicationRunner {

    @Autowired
    private RoutesService routesService;
    @Autowired
    private IgnoreAuthService ignoreAuthService;

    @Override
    public void run(ApplicationArguments args) {
        loadRoutes();

        loadIgnoreAuth();
    }

    private void loadRoutes() {
        log.info(">>> load all routes start");
        routesService.cacheAllRoutes();
        log.info(">>> load all routes end");
    }

    public void loadIgnoreAuth() {
        log.info(">>> load all ignore uri start");
        ignoreAuthService.cacheAllIgnoreAuth();
        log.info(">>> load all ignore uri end");
    }
}
